<?php

namespace app\wechat\controller;

use app\admin\controller\Backend;

/**
 * 微信自动回复管理
 *
 * @icon fa fa-circle-o
 */
class Autoreply extends Backend
{

    protected $noNeedRight = ['check_text_unique'];

    public function _initialize()
    {
        parent::_initialize();
        $this->service = model('wechat/autoreply' ,'service');
    }

    /**
     * 判断文本是否唯一
     * @internal
     */
    public function check_text_unique()
    {
        $row = $this->request->post("row/a");
        $except = $this->request->post("except");
        $text = isset($row['text']) ? $row['text'] : '';
        if ($this->service->check_text_unique($text, $except)){
            return json(['ok' => '']);
        } else {
            return json(['error' => __('Text already exists')]);
        }
    }

}
